#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        printf("i am child process\n");
        sleep(5);
        exit(0);
    }
    
    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    if(rid > 0)
    {
        if(WIFEXITED(status))
            printf("child quit, status: %d, child quit code : %d, child quit signal: %d, coredump: %d\n", status, (status>>8)&0xFF, status&0x7F, (status>>7)&1);
        else
            printf("child quit unnormal\n");
    }
    else
    {
        printf("wait failed\n");
    }

    return 0;
}
